package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.shopping.dto.PanelContentDto;
import com.cskaoyan.shopping.dto.ProductCateDto;
import com.cskaoyan.shopping.dto.ProductForIdDto;
import com.cskaoyan.shopping.service.INcpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author Mr.Tang
 * @since 2022/09/20 21:17
 */
@RestController
public class NcpController {

    @Autowired
    INcpService iNcpService;


    /**
     * 导航栏展示
     * @return
     */
    @GetMapping("/shopping/navigation")
    public ResponseData navigationForCommodity() {

        List<PanelContentDto> panelContentDtoList = iNcpService.navigationForCommodity();

        ResponseUtil responseUtil = new ResponseUtil();

        ResponseData responseData = responseUtil.setData(panelContentDtoList);
        responseData.setMessage("success");
        return responseData;


    }


    /**
     * 列举所有商品种类
     * @return
     */
    @GetMapping("/shopping/categories")
    public ResponseData categoriesForCommodity() {
      List<ProductCateDto> productCateDtoList = iNcpService.categoriesForCommodity();
//      productCateDtoList.stream().sorted()
        ResponseUtil responseUtil = new ResponseUtil();
        ResponseData responseData = responseUtil.setData(productCateDtoList);
        responseData.setMessage("success");
        return responseData;
    }

//    @GetMapping("/shopping/product/{id}")
//    public ResponseData productForCommodity(@NotNull @PathVariable("id") Long id) {
//
//        ProductForIdDto productForIdDto = iNcpService.productForCommodity(id);
//
//        ResponseUtil responseUtil = new ResponseUtil();
//        ResponseData responseData = responseUtil.setData(productForIdDto);
//
//
//        return responseData;
//    }



    /**
     * 查看商品详情
     * @param id
     * @return
     */
    @GetMapping("/shopping/product/{id}")
    public ResponseData productForCommodity(@NotNull @PathVariable("id") Long id) {

        ProductDetailDto productDetailDto = iNcpService.productForCommoditys(id);

        ResponseUtil responseUtil = new ResponseUtil();
        ResponseData responseData = responseUtil.setData(productDetailDto);


        return responseData;
    }




}
